{% extends "base.html" %}

{% block title %}{{action}} Route{% endblock %}
{% block crumb %}&rsaquo; {{action}} Route{% endblock %}

{% block content %}
<h1>{{action}} Route {{route.name}} - {{route.rating}}</h1>
<br>
<table>
	<tr>
		<td>
{% if form %}
	<FORM>
	<INPUT TYPE="BUTTON" VALUE="View Route" ONCLICK="window.location.href='/routes/viewroute/{{route.id}}'">
	</FORM>
{% else %}
	<FORM>
	<INPUT TYPE="BUTTON" VALUE="Rate Route" ONCLICK="window.location.href='/routes/rateroute/{{route.id}}'">
	</FORM>
{% endif %}

		</td>
{% if setter %}
		<td>
	<FORM>
	<INPUT TYPE="BUTTON" VALUE="Edit Route" ONCLICK="window.location.href='/routes/editroute/{{route.id}}'">
	</FORM>
		</td>
		<td>
	<FORM>
	<INPUT TYPE="BUTTON" VALUE="Generate QR" ONCLICK="window.location.href='/routes/qr/{{route.id}}'">
	</FORM>
		</td>
{% endif %}
	</tr>
</table>
  <table>
	  <tr>
		  <td>
	      {% if route.image %}
		  <img src="{{route.image.url}}" class="profile">
		  <br>
	      {% endif %}
		  {{route.description}}
		  <br>
		  <br>
		  Set by <a href ="/userprofile/view/{{route.setter.id}}">{{route.setter.first_name}} {{route.setter.last_name}}</a> on {{date_set}}.
		  <br>
		  <br>
		  {% if not route.active %}
		  This route has been taken down
		  {% else %}
		  This route is {{route.color}} and can be found
		  {%if route.number%} on rope {{route.number}} {%endif%} on {{route.region.name}}
		  {% endif %}
		  <br>
		  <br>
		  </td>
		  <td>
			  {% if route_info %}
				<h2>Median Suggested Rating</h2>
				<table>
					<tr>
						<td>Median Rating</td>
						<td>{{route_info.median_suggested}}</td>
					</tr>
				</table>

				<h2>Rating Statistics</h2>
				<table>
					{% for key,value in route_info.mean_ratings.items %}
					<tr>
						<td>{{key}}</td>
						<td>{{value}}</td>
					</tr>
					{% endfor %}
				</table>
				{% endif %}
	 </td></tr>
	  <tr><td>
			  {% if route_info %}
				</table>
				<h2>Comments</h2>
				<table>
				{% for comment in route_info.comments %}
					<tr><td>{{comment}}</td></tr>
				{% endfor %}
				</table>

			  {% endif %}

			  {% if form %}
			  <h2>Rating Form</h2>
				{% if message %}
					{{ message }}
				{% endif %}
				<form action="" method="post">{% csrf_token %}
				<table>
				{%if form.rating.errors %}
					<tr><td>{{form.rating.errors}}</td></tr>
				{% endif %}
				<tr><td>{{form.rating.label}}:
					{{form.rating}}</td>
				</tr>

				<tr><td></td>
					<td>Disagree</td>
				{% for eval in evals %}
				<td class="qcol">{{eval.1}}</td>
				{% endfor %}
					<td>Agree</td>
				</tr>
				{% for field in form %}
				{% if not field.label in non_radio %}
				<tr>
				<td>{{field.label}}</td>
				<td></td>
					{{field}}
				<td></td>
				</tr>
				{% if field.errors %}
				<tr><td>  {{field.errors}} </td></tr>
				{% endif %}
				{% endif %}
				{% endfor %}

				{%if form.comments.errors %}
					<tr><td>{{form.comments.errors}}</td></tr>
				{% endif %}
				<tr><td>{{form.comments.label}}: {{form.comments}}</td></tr>
				<br>
				</table>
				<input type="submit" value="Submit Rating">
				</form>
				{% endif %}

		  </td>
	  </tr>
  </table>
{% endblock %}